﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ly.Web.QianTai
{
    public partial class newscontent : System.Web.UI.Page
    {
        ly.BLL.news newsBLL = new BLL.news();
        ly.Model.news newsModel = new Model.news();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        protected void BindData()
        {
            if (!string.IsNullOrEmpty(Request["nid"]))
            {
                string nid = Request["nid"];
                int nnid = Convert.ToInt16(nid);
                newsModel = newsBLL.GetModel(nnid);
                litNewsTitle.Text = newsModel.news_name;//得到的是标题名字
                litNewsTime.Text = newsModel.news_createtime.Value.ToString("yyyy-MM-dd");//新闻发布时间
                litNewsContent.Text = newsModel.news_content;//新闻内容
                int seetimes = newsModel.news_seetime.Value;//每刷新一次点击次数加一
                seetimes = seetimes + 1;
                newsModel.news_seetime = seetimes;
                litNewsClicks.Text = seetimes.ToString();
                newsBLL.Update(newsModel);
                //if(mhn.news_image!="")
                //{
                //    litNewsImage.Text = "<img src=\"Files/" + mhn.news_image + "\" style=\"max-width:400px;max-height:350px;\"/>";
                //}
            //    string upid = GetId(nid, mhn.news_type.ToString(), true);
            //    if (upid != "")
            //    {
            //        litUp.Text = "<a href=\"content.aspx?nid=" + upid + "\" >" + newsBLL.GetModel(int.Parse(upid)).news_name + "</a>";
            //    }
            //    string nextid = GetId(nid, mhn.news_type.ToString(), false);
            //    if (nextid != "")
            //    {
            //        litNext.Text = "<a href=\"content.aspx?nid=" + nextid + "\" >" + newsBLL.GetModel(int.Parse(nextid)).news_name + "</a>";
            //    }

            }

        }




        protected string GetId(string id, string type, bool isUp)
        {
            string retid = string.Empty;
            DataSet ds = new DataSet();
            string strwhere = "";
            //ds = newsBLL.GetIdList(" news_isshow=1 and news_type=" + type + " order by news_alertime desc");
            ds = newsBLL.GetList(strwhere);
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString() == id)
                    {
                        if (isUp && i > 0)
                        {
                            retid = ds.Tables[0].Rows[i - 1][0].ToString();
                            break;
                        }
                        if (!isUp && i < ds.Tables[0].Rows.Count - 1)
                        {
                            retid = ds.Tables[0].Rows[i + 1][0].ToString();
                            break;
                        }
                    }
                }
            }
            return retid;
        }





    }
}